package ai.people.netmon.framework.domain.archives.vo;

import ai.people.netmon.framework.constant.NumberHideConstant;
import ai.people.netmon.framework.domain.archives.entity.ArchivesBaseInfo;
import ai.people.netmon.utils.NumberUtils;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.ToStringSerializer;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 档案列表返回VO
 *
 * @author zhenglin
 * @since 2022/3/30
 */
@Data
@NoArgsConstructor
public class ArchivesListVO {

    @JSONField(serializeUsing = ToStringSerializer.class)
    private Long id;

    /**
     * 姓名
     */
    private String name;
    /**
     * 性别 0:未知, 1:男 ,2:女
     */
    private Integer gender;

    /**
     * 照片
     */
    private String picture;


    /**
     * 现居地
     */
    private String residentialAddress;

    /**
     * 手机号
     */
    private String phoneNumber;


    /**
     * 标签
     */
    private List<String> tags;


    /**
     * 个人信息
     */
    private String personalSituation;


    /**
     * 创建人
     */
    private String creator;


    public ArchivesListVO(ArchivesBaseInfo baseInfo) {
        this.id = baseInfo.getId();
        this.name = baseInfo.buildName().stream().findFirst().orElse(null);
        this.gender = baseInfo.getGender();
        this.picture = baseInfo.getPicture();
        this.residentialAddress = baseInfo.getResidentialAddress();
        this.phoneNumber = baseInfo.buildPhone().stream().findFirst().map(x -> NumberUtils.hideBit(x, NumberHideConstant.PHONE_HIDE)).orElse(null);
        this.tags = baseInfo.buildTags();
        String archivesJudgment = baseInfo.getArchivesJudgment();
        this.personalSituation = StringUtils.isBlank(archivesJudgment) ? baseInfo.getPersonalSituation() : archivesJudgment;
        this.creator = baseInfo.getCreatorName();
    }

}
